#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int  argc, char  **argv)
{
  FILE  *input;
  FILE  *output;
  char  *begin;
  char  *end;
  char  URL[1024];
  char  line[100000];
  char  buffer[1000];
  int   i;

  output = fopen("spells.txt","w");
  for (i = 1; i < 100000; i++)
  {
    fprintf(output,"%d|", i);
    sprintf(URL,"wget -O input http://www.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"name: '")) && (strstr(line,"g_pageInfo")))
      {
        begin += 7;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fclose(input);
    fprintf(output,"|");

    sprintf(URL,"wget -O input http://fr.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"name: '")) && (strstr(line,"g_pageInfo")))
      {
        begin += 7;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fclose(input);
    fprintf(output,"|");

    sprintf(URL,"wget -O input http://de.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"name: '")) && (strstr(line,"g_pageInfo")))
      {
        begin += 7;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fclose(input);
    fprintf(output,"|");

    sprintf(URL,"wget -O input http://es.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"name: '")) && (strstr(line,"g_pageInfo")))
      {
        begin += 7;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fclose(input);
    fprintf(output,"|");

    sprintf(URL,"wget -O input http://ru.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"name: '")) && (strstr(line,"g_pageInfo")))
      {
        begin += 7;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fclose(input);
    fprintf(output,"|");

    sprintf(URL,"wget -O input http://www.wowhead.com/?spell=%d",i);
    system(URL);
    input = fopen("input","r");
    while (fgets(line, 100000, input))
    { 
      if ((begin = strstr(line,"Icon.create('")))
      {
        begin += 13;
        end = strstr(begin,"'");
        strncpy(buffer,begin,end-begin);
        buffer[end-begin] = '\0';
        printf(line);
        fprintf(output,"%s", buffer);
        break;
      }
    }
    fprintf(output,"\n");
    fflush(output);

    fclose(input);
  }
  fclose(output);
}
